{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Created by william from lexueoude.com. 更多正版技术视频讲解，公众号 1.乐学偶得（lexueoude）2.乐学FinTech (LoveShareFinTech)\n",
    "\n",
    "unknown unknown\n",
    "known unknown\n",
    "\n",
    "\n",
    "Having endeavored to forecast exchange rates for more than half a century, I have understandably developed significant humility about my ability in this area.\n",
    "--Alan Greenspan\n",
    "\n",
    "1.Pair Quotation : 1.13  EUR/USD (base currency , price currency)?\n",
    "\n",
    "2.Nominal and Real Exchange Rate:$FX_{real}(f/d) = FX_{nominal} (f/d)* CPI_f/CPI_d $"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.293142857142857\n"
     ]
    }
   ],
   "source": [
    "base_year_CPI_US=100\n",
    "base_year_CPI_Europe=100\n",
    "\n",
    "#The exchange rate is $ 1.1315 per euro\n",
    "the_exchange_rate_now=1.1315\n",
    "\n",
    "this_year_CPI_US=105\n",
    "this_year_CPI_Europe=120\n",
    "\n",
    "the_real_FX=the_exchange_rate_now*(this_year_CPI_Europe/this_year_CPI_US)\n",
    "print(the_real_FX)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bid-Ask(Offer) Spread:\n",
    "\n",
    "1.bid price: bank/ dealer pay FC per unit\n",
    "\n",
    "2.ask price: bank/dealer sell FC per unit\n",
    "\n",
    "3.8 pips:0.0008(base point bp)\n",
    "\n",
    "Dealer:\n",
    "1.Wider than InterBank spread\n",
    "2.Size of the transaction\n",
    "3.Relationship\n",
    "......\n",
    "\n",
    "\n",
    "InterBank:\n",
    "1.Currencies difference(e.g , USD/EUR,USD/JPY, USD/GBP)\n",
    "2.Time (New York 8:00 - 11:00 a.m , London)\n",
    "3.Market Condition(Volatility) Spread\n",
    "4.Maturity\n",
    ".......\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.Cross Rate Calculation:\n",
    "EUR/USD 1.1315 1.1316\n",
    "USD/JPY 110.36 110.38\n",
    "\n",
    "\n",
    "EUR/JPY ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'bid': 124.90544799999999, 'ask': 124.971664}\n",
      "124.938556\n"
     ]
    }
   ],
   "source": [
    "EUR_USD={\"bid\":1.1318,\n",
    "         \"ask\":1.1324}\n",
    "\n",
    "USD_JPY={\"bid\":110.36,\n",
    "         \"ask\":110.36}\n",
    "\n",
    "print({k: EUR_USD[k]*USD_JPY[k] for k in EUR_USD})\n",
    "print(sum(EUR_USD[k]*USD_JPY[k] for k in EUR_USD)/2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.Interbank Market\n",
    "2.Dealer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'bid': 124.90544799999999, 'ask': 124.98298800000002}\n",
      "{'bid': 125, 'ask': 126}\n"
     ]
    }
   ],
   "source": [
    "# This is the quote of Interbank market\n",
    "Inter_EUR_USD={\"bid\":1.1318,\n",
    "         \"ask\":1.1324}\n",
    "\n",
    "Inter_USD_JPY={\"bid\":110.36,\n",
    "         \"ask\":110.37}\n",
    "\n",
    "#This is the quote of Dealers market\n",
    "\n",
    "Dealer_EUR_JPY={\"bid\":125,\n",
    "                \"ask\":126}\n",
    "\n",
    "print({k: Inter_EUR_USD[k]*Inter_USD_JPY[k] for k in Inter_EUR_USD})\n",
    "# print(sum(Inter_EUR_USD[k]*Inter_USD_JPY[k] for k in Inter_EUR_USD)/2)\n",
    "print(Dealer_EUR_JPY)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.Begin with USD: USD->EUR->JPY->USD\n",
    "\n",
    "1/1.1324*125/110.37\n",
    "\n",
    "2.Begin with JPY: JPY->USD->EUR->JPY\n",
    "\n",
    "1/110.37/1.1324*125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00013611452464212803\n"
     ]
    }
   ],
   "source": [
    "print((1/1.1324*125/110.37)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00013611452464212803\n"
     ]
    }
   ],
   "source": [
    "print((1/110.37/1.1324*125)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}